// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

type Queue []int

func (qu Queue) Push(element int) Queue {
	// 追加元素到队列中
	qu = append(qu, element)
	fmt.Println("Push:", element)
	return qu
}

func (qu Queue) Pop() Queue {
	// 第1个元素是要出队的元素
	element := qu[0]
	fmt.Println("Pop:", element)
	// 一旦元素出队，就将其删掉
	return qu[1:]
}

func main() {
	// 创建一个整数队列
	var queue Queue

	queue = queue.Push(1)
	queue = queue.Push(6)
	queue = queue.Push(8)
	fmt.Println("Queue:", queue)
	queue = queue.Pop()
	fmt.Println("Queue:", queue)
	queue = queue.Push(9)
	fmt.Println("Queue:", queue)
}

//$ go run queue.go
//Push: 1
//Push: 6
//Push: 8
//Queue: [1 6 8]
//Pop: 1
//Queue: [6 8]
//Push: 9
//Queue: [6 8 9]
